home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Mac F2C v1.3.5 Documentation.rsrc / TEXT_134.txt < prev    next >
Text File  |  1997-06-15  |  17KB  |  433 lines

  1. Scripting Mac F2C
  2.  
  3.  
  4. Introduction and Quick-Start
  5.  
  6. Mac F2C is AppleEvent savvy.  It supports drag-&-drop translation.  More importantly, you can drive Mac F2C translations entirely using AppleEvents.  
  7.  
  8. The AppleEvent implementation in Mac F2C v1.3 is based on Apple窶冱 Object Model and utilizes a subset of the Core Suite.  Events from the Core Suite are used to get and set the various options available in Mac F2C.  For detailed information on the events in the Core Suite refer to the AppleEvent Registry.  Mac F2C also supports a custom 窶廡ORTRAN-to-C Suite窶 that provides two different AppleEvents for translating FORTRAN to C:
  9.  
  10. 窶「 The first custom AppleEvent (the f2c AppleEvent) accepts a list of files and allows you to pass option choices to the translator in a UNIX-style option string (see the chapter 窶弑NIX f2c Option Switch Syntax窶 for more information on the UNIX-style option switches).  The f2c AppleEvent ignores any option settings specified in the FORTRAN Options, C Options, Prototyping Options, Warning Options, and Advanced Options dialogs (it does, however, use the settings in the Compiler Interactions and Mac F2C Preferences dialogs).
  11.  
  12. 窶「 The second AppleEvent (the translate AppleEvent) only accepts a list of files.  It uses the all of the options settings specified in the various Options dialogs.  You can use the get/set AppleEvents (from the Core Suite) to set the options as desired prior to sending a translate AppleEvent. 
  13.  
  14. Which of these two AppleEvents you use is purely a matter of personal 
  15. choice.
  16.  
  17. Some sample AppleScripts are included as part of the Mac F2C distribution package, in the Mac F2C Extras folder.  They were written using v1.1 of the AppleScript邃「 extension and v1.1 of the AppleScript Editor.  These scripts illustrate how to use the various events to control Mac F2C.  The easiest way to drive Mac F2C from your own scripts is simply to copy and paste appropriate portions of the sample scripts into yours andthenmodify them as required.  Mac F2C also includes a full aete resource, so you can get detailed information on the exact syntax of the AppleEvents supported by Mac F2C from its dictionary.
  18.  
  19.  
  20. Changes from Mac F2C v1.2
  21.  
  22. Mac F2C now supports Apple窶冱 Object Model and implements a subset of the Core Suite.
  23.  
  24. The translate AppleEvent no longer accepts optional parameters specifying the value of the various option settings.  Each option now corresponds to a property of the application and can be accessed using the Core Suite get and set AppleEvents.  Refer to the dictionary for the names of the properties.
  25.  
  26.  
  27.  
  28.  
  29. THE DETAILS
  30.  
  31.  
  32. The remainder of this chapter provides more detailed information for users who wish to know more details about sending AppleEvents to Mac F2C.  In particular, the information below has all the information needed to write code that sends AppleEvents to Mac F2C.  If you simply want to write an AppleScripts to drive Mac F2C, refer instead to the scripting dictionary built into the Mac F2C application itself.
  33.  
  34. The constants appearing in this typeface below are defined for you in the file F2cAETerms.h, which is included in the Mac F2C Extras folder.  You can #include this file in any C/C++ source file you write that sends AppleEvents to Mac F2C.
  35.  
  36.  
  37. Classes
  38.  
  39. 窶「 cApplication:
  40.     the application:  one instance, the Mac F2C application
  41.  
  42. 窶「 cWindow:
  43.     a Macintosh window:  one instance, the status window
  44.  
  45.  
  46.  
  47. Containment Hierarchies
  48.  
  49. "null"                     (the topmost object )
  50.     cApplication          (Mac F2C, synonymous with "null")
  51.         cWindow                (translation status window [only 1 window])
  52.  
  53.  
  54.  
  55. Class Properties
  56.  
  57. 窶「 cApplication:
  58.  
  59. < FORTRAN Input Options >
  60.  
  61. pCheckSubscripts        
  62.       typeBoolean         
  63.       Check subscripts are within array bounds at run time.
  64. pDoLoopsOnce
  65.       typeBoolean         
  66.       Perform DO loops at least once if reached (FORTRAN-66 rules).
  67. pDefaultVariableType
  68.       typeEnumeration
  69.       Default type of undeclared variables is:
  70.           kUndefined        - undefined (= error message)
  71.           kFortranRules - default FORTRAN rules (= first letter I-M -> integer)
  72. pFreeFormatInput
  73.       typeBoolean
  74.       Assume free-format input.
  75. pCutAtColumn72
  76.       typeBoolean
  77.       Treat text appearing after column 72 as an error.
  78. pDoubleComplex
  79.       typeBoolean
  80.       Implicitly recognize DOUBLE COMPLEX.
  81. pBackslashEscapes 
  82.       typeBoolean
  83.       Recognize backslash escapes in character strings.
  84. pIntegerSize
  85.       typeEnumeration
  86.       Size of INTEGER & LOGICAL variables (INTEGER*4 always 4-bytes):
  87.           k4Byte  - 4 bytes
  88.           k2Byte  - 2 bytes
  89. pInteger8
  90.       typeBoolean
  91.       Allow INTEGER*8 declarations.
  92.  
  93. < C Output Options >
  94.  
  95. pCodeGenerated
  96.       typeEnumeration
  97.       The variety of C code to generate:
  98.           kKrC     - K&R C code
  99.           kAnsiC  - ANSI C code
  100.           kCpp      - C++ code
  101. pHonorCase
  102.       typeBoolean
  103.       Honor case of variable and external names.
  104. pLocalVariables
  105.       typeEnumeration
  106.       Storage class for local variables:
  107.           kAutomatic  - automatic (= stack) storage
  108.           kStatic          - static (= like globals) storage
  109. pAlignCharStrings
  110.       typeBoolean
  111.       Align char strings on words (FORTRAN-66 style Hollerith).
  112. pCommonAsExtern
  113.       typeBoolean
  114.       Declare uninitialized COMMON to be "Extern".
  115. pCommonSeparate  
  116.       typeBoolean
  117.       Place uninitialized COMMON blocks in separate files.
  118. pCommonLookLocal
  119.       typeBoolean
  120.       Make COMMON block members look like local variables.
  121. pFortranEvaluation
  122.       typeBoolean
  123.       Use temp values to force FORTRAN order of evaluation.
  124. pDoublePrecision
  125.       typeBoolean
  126.       Perform all floating-point operations in double precision.
  127. pCastRealFunctions
  128.       typeBoolean
  129.       Cast values of REAL functions to REAL (including intrinsics).
  130. pPromoteSingleToDouble
  131.       typeBoolean
  132.       Promote REAL to DOUBLE PRECISION, COMPLEX to DOUBLE COMPLEX.
  133. pMultiDimSubscripts
  134.       typeBoolean
  135.       Preserve multidimensional subscripts.
  136.  
  137. < Prototype Generation Options >
  138.  
  139. pPrototypes
  140.       typeEnumeration
  141.       Controls generate prototypes:
  142.           kCodeOnly             - code only, no prototypes
  143.           kCodeAndProtos  - both code and prototypes
  144.           kProtosOnly         - no code, only prototypes
  145. pRetranslate
  146.       typeBoolean
  147.       Re-translate if prototypes or declarations may change.   
  148. pInferTypes
  149.       typeBoolean
  150.       Infer the type of untyped EXTERNAL functions used only 
  151.          as parameters to previously defined procedures.
  152.  
  153. < Warnings Issued Options >
  154.  
  155. pSourceAsComments
  156.       typeBoolean
  157.       Include the original FORTRAN source as comments .    
  158. pLineNumbers
  159.       typeBoolean
  160.       Include the original FORTRAN line numbers in 窶œ#line窶 lines.
  161. pRejectFortran77
  162.       typeBoolean
  163.       Reject extensions to the FORTRAN-77 standard
  164. pWarnings
  165.       typeEnumeration
  166.       Suppress the following warnings (list permitted):
  167.           kNoWarnings       - none
  168.           kF66Warnings    - suppress FORTRAN-66 compatibility warnings
  169.           kAlignWarnings  - suppress odd-alignment warnings caused by
  170.                                                EQUIVALENCE/COMMON statements
  171.           kAllWarnings      - suppress all warning messages
  172.     
  173. < Advanced Options >
  174.  
  175. pEquivalences           
  176.       typeShortInteger 
  177.       Maximum number of equivalences.
  178. pExternals
  179.       typeShortInteger
  180.       Maximum number of external symbols.
  181. pStatementLabels
  182.       typeShortInteger
  183.       Maximum number of statement labels.
  184. pNesting
  185.       typeShortInteger
  186.       Maximum nesting of control structures.
  187. pNames
  188.       typeShortInteger
  189.       Maximum number of names.
  190. pLiterals
  191.       typeShortInteger
  192.       Maximum number of literal constants.
  193. pContinuations
  194.       typeShortInteger
  195.       Maximum number of continuation lines.
  196. pImpliedLabels
  197.       typeShortInteger
  198.       Maximum number of implied labels.
  199.  
  200. < Compiler Interaction Options >
  201.  
  202. pInteractWith
  203.       typeEnumeration
  204.       Which C compilers to interact with:
  205.           kCompilerNone      - none
  206.           kCompilerTPM       - THINK Project Manager (68k)
  207.           kCompilerSPM       - Symantec Project Manager (PPC)
  208.           kCompilerCW68K  - CodeWarrior 68K
  209.           kCompilerCWPPC  - CodeWarrior PPC
  210.           kCompilerCWIde     - CodeWarrior IDE (v1.3)
  211. pInteractHow
  212.       typeEnumeration
  213.       What kind of interaction to have with C compilers:
  214.           kNoInteraction   - none
  215.           kTouchFiles        - touch files generated by Mac F2C
  216.           kCompileFiles    - compile files generated by Mac F2C
  217.           kUpdateProject  - update whole projects containing files 
  218.                                                generated by Mac F2C
  219.           kBuildTarget       - build targets of projects containing files 
  220.                                                generated by Mac F2C
  221. pInteractAddFiles
  222.       typeBoolean
  223.       Add files generated by Mac F2C to project files as required.
  224.  
  225. < Mac F2C Preference Options >
  226.  
  227. pSkipNonFORTRAN
  228.       typeBoolean
  229.       Silently skip non-FORTRAN files.
  230. pOutputFileType
  231.       typeType
  232.       Creator type for output files.
  233.  
  234.  
  235. 窶「 cWindow:
  236.     
  237. <none>
  238.       No properties implemented.
  239.         
  240.         
  241.  
  242. Object Specification
  243.  
  244. 窶「 cApplication:
  245.  
  246. formName                               "¥pMac F2C"
  247.  
  248. 窶「 cWindow:
  249.  
  250. formAbsolutePosition        1 (there is only one window)
  251.  
  252.  
  253.  
  254. Events
  255.  
  256. Required Suite
  257.  
  258. Mac F2C supports the four required Apple Events: open application, open documents, print documents, and quit application.  These events behave as follows:
  259.  
  260. 窶「 open <application>: No unusual actions are performed.
  261.     
  262. 窶「 open <documents>:  Documents listed are translated into C using the default options settings.  An error message is issued if the document name does not end in 窶œ.f窶 or  窶œ.F窶.  An open event is equivalent to a translate event (see below) with no optional parameters. 
  263.                         
  264. 窶「 print <documents>:  Silently ignored; Mac F2C does not print any documents.  
  265.     
  266. 窶「 quit:  Quits Mac F2C.
  267.     
  268. Note that Mac F2C does not own any files (i.e., there are no files of type Mac F2C except for the application itself).  The open event is used to support drag-&-drop operations.  This allows you to translate a bunch of FORTRAN files by dragging them and dropping them on top of Mac F2C.  The print event is supported to allow printing of the status window, NOT printing of source code or other documents.
  269.  
  270. More detailed descriptions of the required events follow:
  271.  
  272. 窶「 open <application>
  273. Start the application with no documents to pass 
  274. (Mac F2C starts and waits for user commands)
  275. Class:               kCoreEventClass
  276. ID:                    kAEOpenApplication    
  277. Parameters:     <none>
  278.         
  279. 窶「 open <document>                       
  280. Open a list of documents
  281. (Mac F2C will translate each one using current option settings)
  282. Class:               kCoreEventClass
  283. ID:                    kAEOpenDocuments
  284. Parameters:
  285.     keyDirectObject
  286.            required 
  287.        typeAlias                
  288.        List of documents to open
  289.  
  290. 窶「 print <document>
  291. Print a list of documents
  292. (Mac F2C ignores this AppleEvent when passed documents)
  293. Class:               kCoreEventClass
  294. ID:                    kAEPrintDocuments
  295. Parameters:
  296.     keyDirectObject
  297.        required
  298.        typeAlias
  299.        List of documents to print
  300.         
  301. 窶「 quit
  302. Quit the application
  303. Class:               kCoreEventClass
  304. ID:                    kAEQuitApplication
  305. Parameters:     <none>    
  306.    
  307.  
  308. Core Suite Subset
  309.  
  310. Mac F2C supports several events from the Core Suite.  Most important of these are the get and set events.  Use these events to examine and change the value of the various properties that correspond to the Mac F2C options.  Detailed descriptions of these events follow:
  311.  
  312. 窶「 save <window>
  313. Save the translation status window contents
  314. Class:               kAECoreSuite
  315. ID:                    kAESave
  316. Parameters:
  317.     keyDirectObject
  318.        required
  319.        cObjectSpecifier
  320.        Object to be saved
  321.         
  322. 窶「 print <window>
  323. Print the translation status window contents
  324. Class:               kCoreEventClass
  325. ID:                    kAEPrint
  326. Parameters:
  327.     keyDirectObject
  328.        required
  329.        cObjectSpecifier
  330.        Object to be printed
  331.  
  332. 窶「 get <property>
  333. Get a property
  334. Class:               kAECoreSuite
  335. ID:                    kAEGetData
  336. Parameters:
  337.     keyDirectObject
  338.        required
  339.        cObjectSpecifier
  340.        Object whose data is to be returned
  341.     keyAERequestedType
  342.        optional
  343.        cType
  344.        List of preferred returned data types
  345. Reply parameters:
  346.     keyAEResult
  347.        typeWildCard
  348.        The data requested
  349.  
  350. 窶「 set <property>
  351. Set a property
  352. Class:               kAECoreSuite
  353. ID:                    kAESetData
  354. Parameters:
  355.     keyDirectObject
  356.        required
  357.        cObjectSpecifier
  358.        Object to be changed
  359.     keyAEData
  360.        required
  361.        typeWildCard
  362.        The new value
  363.     
  364.  
  365. FORTRAN-to-C Suite
  366.  
  367. The FORTRAN-to-C Suite is a set of AppleEvents that can be used to control the translation of FORTRAN files to C files.  The FORTRAN-to-C Suite consists of two AppleEvents differing in how options are passed to the f2c kernel.  
  368.  
  369. The first AppleEvent (the f2c event) mimics the operation of the original f2c program on UNIX machines.  In this AppleEvent options for the f2c kernel are passed as a single string of UNIX-style option settings.  This AppleEvent ignores any option settings specified in the FORTRAN Input, C Output, Prototype Generation, Warnings Issued, and Advanced Options dialogs (it does, however, use the settings in the Compiler Interface and Mac F2C Preferences dialogs).  This means that if you do not include a UNIX-style option string, then NO option switches are passed to the f2c kernel.
  370.  
  371.  
  372. The second AppleEvent (the translate event) is more 窶廴acintosh窶 in that it takes a list of files and translates them using the current settings of the options (which can be controlled using get/set events).
  373.  
  374. These two events are:
  375.  
  376. 窶「 f2c:  Translate the specified files (one or more) from FORTRAN to C using a UNIX-style string of options.
  377.                     
  378. 窶「 translate:  Translate the specified files (one or more) from  FORTRAN to C using the current option settings.
  379.                     
  380. IMPORTANT NOTE:  Both of these events return an error code (keyErrorNumber) only if Mac F2C could not process your AppleEvent.  If Mac F2C was able to successfully process your AppleEvent, then the result (keyAEResult) will contain the return code from the f2c kernel (otherwise there will be no result).  To be sure that Mac F2C correctly translated a file, you must (a) first make sure there were no errors processing your event and then (b) check that the result of the event is 0 (zero).  This may sound a bit convoluted, but it is in fact the way things are supposed to work.  And if you think about it a bit it actually makes a lot of sense.
  381.  
  382. More detailed descriptions of the FORTRAN-to-C events follow:
  383.  
  384. 窶「 f2c <FORTRAN files> 
  385. This event causes Mac F2C translate one or more FORTRAN files.  The options for the f2c kernel are specified by a UNIX-style set of switches (e.g.  "-A -P -w -f"; see the chapter on UNIX f2c Option Switch Syntax for more information on the switches and their meaning).  The current option settings in the FORTRAN Input, C Output, Prototype Generation, Warnings Issued, and Advanced Options dialogs are ignored (however, the settings in the Compiler Interface and Mac F2C Preferences dialogs are used).  This means that if you do not include a UNIX-style option string, then no option switches are passed to the f2c kernel.
  386. Class:               kF2CEventClass
  387. ID:                    kAEf2cEvent
  388. Parameters:
  389.     keyDirectObject
  390.        required
  391.        typeAlias
  392.        List of FORTRAN files to translate
  393.     keyUnixCmdStr
  394.        optional
  395.        typeChar
  396.        UNIX-style option string
  397. Reply parameters:
  398.     keyAEResult
  399.        typeInteger
  400.        List of the return codes from the f2c kernel, one per file translated
  401.     keyErrorNumber
  402.        typeLongInteger
  403.        Error code if unable to process your event; not provided if no 
  404.        processing errors occur; compile results (including compile errors) 
  405.        are returned in keyAEResult.
  406.     keyErrorString
  407.        typeChar
  408.         Error message whenever keyErrorNumber is non-zero
  409.  
  410. 窶「 translate <FORTRAN files>
  411. This event will have Mac F2C translate a list of FORTRAN file.  Current 
  412. option settings are used.  You can change the option settings by using the 
  413. get and set AppleEvents.
  414. Class:               kF2CEventClass
  415. ID:                    kAETranslateEvent
  416. Parameters:
  417.     keyDirectObject
  418.        required
  419.        typeAlias
  420.        List of FORTRAN files to translate
  421. Reply parameters:
  422.     keyAEResult
  423.        typeInteger
  424.        List of the return codes from the f2c kernel, one per file translated
  425.     keyErrorNumber
  426.        typeLongInteger
  427.        Error code if unable to process your event; not provided if no 
  428.        processing errors occur; compile results (including compile errors) 
  429.        are returned in keyAEResult.
  430.     keyErrorString
  431.        typeChar
  432.         Error message whenever keyErrorNumber is non-zero
  433.